package com.ncloud.act.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.act.entity.ChnlPayLog;

@Mapper
public interface ChnlPayLogMapper{

	@Select("SELECT t1.charge_id, t1.chnl_id,t2.chnl_name,t2.chnl_type, t1.recv_type, t1.recv_fee, date_format(t1.recv_time, '%Y-%m-%d %H:%i:%s' ) as recv_time, t1.recv_user_id,"
			+ "(select ifnull(account,'') from sys_user t where t.id=t1.recv_user_id) as account,"
			+ "t1.remark "
			+ "FROM sys_chnl_paylog t1 left join sys_chnl t2 on t1.chnl_id=t2.chnl_id "
			+ "where t1.recv_time >=#{1} and  t1.recv_time <=#{2} "
			/*+ "and t1.chnl_id in (SELECT chnl_id FROM  sys_chnl where chnl_id = #{0} "
			+ "union all "
			+ "SELECT chnl_id FROM  sys_chnl where parent_id = #{0}) "*/
			+ "and FIND_IN_SET(t1.chnl_id,f_getChnlList(#{0})) "
			+ "order by recv_time desc ")
	@Results({
		@Result(javaType=String.class,column="charge_id",property="charge_id"),@Result(javaType=String.class,column="chnl_id",property="chnl_id"),
		@Result(column="recv_type",property="recv_type"),@Result(column="recv_fee",property="recv_fee"),
		@Result(column="recv_time",property="recv_time"),@Result(column="recv_user_id",property="recv_user_id"),
		@Result(column="remark",property="remark")})
	List<JSONObject> getChnlPayLogByChnlID(Integer user_id,String begin_time,String end_time);
	
	@Insert(value = "INSERT INTO sys_chnl_paylog (charge_id, chnl_id, recv_type, recv_fee, recv_time, recv_user_id, remark) "
										+ "values(#{charge_id},#{chnl_id},#{recv_type},#{recv_fee},#{recv_time},#{recv_user_id},#{remark})")
    public int insertChnlPayLog(ChnlPayLog chnlPayLog);
	
	/*@Update(value = "UPDATE sys_chnl_paylog SET deposit_money = #{deposit_money},update_time = #{update_time}, update_user_id = #{update_user_id} WHERE chnl_id = #{chnl_id} ")
    public int updateChnlPayLog(ChnlPayLog chnlPayLog);*/
}
